package com.ruoyi.crm.sale.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.sale.domain.CrmBusinessType;
import com.ruoyi.crm.sale.service.ICrmBusinessTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商机状态组类别Controller
 * 
 * @author ruoyi
 * @date 2021-09-09
 */
@RestController
@RequestMapping("/crm/type")
public class CrmBusinessTypeController extends BaseController
{
    @Autowired
    private ICrmBusinessTypeService crmBusinessTypeService;

    /**
     * 查询商机状态组类别列表
     */
    @PreAuthorize("@ss.hasPermi('crm:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmBusinessType crmBusinessType)
    {
        startPage();
        List<CrmBusinessType> list = crmBusinessTypeService.selectCrmBusinessTypeList(crmBusinessType);
        return getDataTable(list);
    }

    /**
     * 查询所有商机分类
     */
    @PreAuthorize("@ss.hasPermi('crm:type:list')")
    @GetMapping("/getAllListType")
    public AjaxResult getAllListType(CrmBusinessType crmBusinessType)
    {
        List<CrmBusinessType> list = crmBusinessTypeService.selectCrmBusinessTypeList(crmBusinessType);
        return AjaxResult.success(list);
    }

    /**
     * 导出商机状态组类别列表
     */
    @PreAuthorize("@ss.hasPermi('crm:type:export')")
    @Log(title = "商机状态组类别", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmBusinessType crmBusinessType)
    {
        List<CrmBusinessType> list = crmBusinessTypeService.selectCrmBusinessTypeList(crmBusinessType);
        ExcelUtil<CrmBusinessType> util = new ExcelUtil<CrmBusinessType>(CrmBusinessType.class);
        return util.exportExcel(list, "商机状态组类别数据");
    }

    /**
     * 获取商机状态组类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmBusinessTypeService.selectCrmBusinessTypeById(id));
    }

    /**
     * 新增商机状态组类别
     */
    @PreAuthorize("@ss.hasPermi('crm:type:add')")
    @Log(title = "商机状态组类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmBusinessType crmBusinessType)
    {
        return toAjax(crmBusinessTypeService.insertCrmBusinessType(crmBusinessType));
    }

    /**
     * 修改商机状态组类别
     */
    @PreAuthorize("@ss.hasPermi('crm:type:edit')")
    @Log(title = "商机状态组类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmBusinessType crmBusinessType)
    {
        return toAjax(crmBusinessTypeService.updateCrmBusinessType(crmBusinessType));
    }

    /**
     * 删除商机状态组类别
     */
    @PreAuthorize("@ss.hasPermi('crm:type:remove')")
    @Log(title = "商机状态组类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmBusinessTypeService.deleteCrmBusinessTypeByIds(ids));
    }
}
